package com.liang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liang.entity.CNotice;
import com.liang.mapper.CNoticeMapper;
import com.liang.service.CNoticeService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @name: CNoticeServiceImpl
 * @author: 李昂
 * @date: 2020-12-31 20:05
 * @description：CNoticeServiceImpl
 * @update: 2020-12-31 20:05
 */
@Service
@CacheConfig(cacheNames = "CNoticeMapper")
public class CNoticeServiceImpl extends ServiceImpl<CNoticeMapper, CNotice> implements CNoticeService {

    //添加社团公告
    @Override
    @CacheEvict(value = "notice", allEntries = true)
    public boolean addNotice(CNotice notice) {
        return this.save(notice);
    }

    //获取社团公告
    @Override
    @Cacheable(value = "notice")
    public List<CNotice> getNotice(String id) {
        if (id == null) {
            return this.list();
        } else {
            LambdaQueryWrapper<CNotice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(CNotice::getNid, id);
            return this.list(lambdaQueryWrapper);
        }
    }

    @Override
    @CacheEvict(value = "notice", allEntries = true)
    public boolean delNotice(int id) {
        return this.removeById(id);
    }
}
